<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/21 0021
 * Time: 下午 1:39
 */
namespace Admin\Model;
use Think\Model;
class DivisionModel extends Model{

    public function get_list ($map, $star, $end){
        return $this->where ($map)
            ->where ("status=1")
            ->limit ($star, $end)
            ->select ();
    }

    //获取小组下的users
    public function get_users_group ($did){
        return $this->where ('id='.$did)
            ->getField('users');
    }
    public function get_users_shop ($sid){
        $groups =  $this->where (array ('shop'=>array ('in', $sid)))
                        ->select ();
        $users = '';
        foreach ($groups as $gr){
            $users .= $gr['users'];
        }
        return trim($users, ',');
    }
    //获取店铺下所有分组
    public function get_groups_in_shop ($shopid=''){
        if (empty ($shopid)){
            return $this->where (array ('status'=>1))
                ->select ();
        }else {
            return $this->where (array ('shop_id'=>$shopid, 'status'=>1))
                ->select ();
        }

    }

}